/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package post;
import java.io.*;
import java.util.*;

/**
 *
 * @author sean
 */
public class Catalog {
    private ArrayList<ProductSpec> productList = new ArrayList<ProductSpec>();

    public Catalog( File fileName ) throws FileNotFoundException, IOException
    {
        ProductReader reader = new ProductReader(fileName);
        while( reader.hasMoreProducts() )   //while file has more products
        {
            productList.add(reader.getNextProduct());   //add product spec from file
        }
    }//end constructor

    public ProductSpec getSpec( String upc ) //find a product spec matching upc
    {
        Iterator it = productList.iterator();
        while( it.hasNext() )
        {
            ProductSpec tempSpec = (ProductSpec) it.next(); //iterate through list of product specs
            if( tempSpec.getUpc().equals(upc) ) //if found a match
            {
                return tempSpec;    //returns spec matching upc
            }
                
        }
        return null;    //upc not found
    }

}//end Catalog class
